package cn.com.dashihui.pay.SQ.test;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.jfinal.kit.PropKit;

import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.junit.Test;

import com.jfinal.kit.PropKit;

import cn.com.dashihui.kit.CommonKit;
import cn.com.dashihui.kit.DatetimeKit;
import cn.com.dashihui.pay.SQ.Kit.MD5;
import cn.com.dashihui.pay.SQ.Kit.MD5Utils;
import cn.com.dashihui.pay.SQ.Kit.ParamUtils;

public class SQPaytest {
//	public static String  custName = "兰雅健";
//	public static String  phoneNo = "15538277550";
//	public static String  cardNo = "6222021705014695244";
//	public static String  bankCode = "ICBC";
//	public static String  idNo = "410381199405292016";
//	public static String  idType = "0";
//	public static String  reqMsgId = "4635746";	//单号
//	public static String  cardType = "1";
//	public static String  authMsg = "075216";	//认证返回的验证码
//	public static String  custType = "02";
//	public static String  payAmount = "0.01";
//	
//	public static String  phone = "15538277550";
//	public static String  merOrderNo = "";	//TODO 订单号  和短信的一样
//	public static String  NotifyURL = "";	//TODO 
	
	@Test
	public void text() throws Exception{

		PropKit.use("config.properties");
		String orderid = "M"+DatetimeKit.getFormatDate("yyyyMMddHHmmssSSS");
		System.out.println("sss"+orderid);
//		Map dataMap = new HashMap<String ,String>();
//		dataMap.put("custName", "兰雅健");
//		dataMap.put("phoneNo", "15538277550");
//		dataMap.put("cardNo", "6222021705014695244");
//		dataMap.put("bankCode", "ICBC");
//		dataMap.put("idNo", "410381199405292016");
//		dataMap.put("reqMsgId", "");
//		dataMap.put("authMsg", "");
//		dataMap.put("payAmount", "0.01");
//		dataMap.put("merOrderNo", "G20190722133856897641");
//		dataMap.put("txnTime", "2019-07-17 11:12:47");
//		dataMap.put("smsCode", "819553");
		
//		dataMap.put("bankOrderNo", "0717111505411347");//支付订单号
//		dataMap.put("Orderno", "203717197171112478896495");	//双乾流水号
//		
//		dataMap.put("refundNo", "");
		//查询签约
//		querySignResult(dataMap);
		//签约/认证custType 02签约  01认证
//		Contract(dataMap);
		// TODO 解约  接口问题先不做
//		breakContract(dataMap);
		//支付短信
//		payMsg(dataMap);
		//交易接口
//		pay(dataMap);
		//交易结果查询
//		queryPay(dataMap);

		//退款申请
//		refundApp(dataMap);
		//退款查询
//		queryRefund(dataMap);
	}
//	public static void main(String[] args) throws Exception{
//		
//	}
	
	//退款查询 TODO
	public static void queryRefund(Map dataMap) throws Exception {
	// TODO Auto-generated method stub
		Map reqMap = new HashMap();
		reqMap.put("merchantno", ParamUtils.toString(PropKit.get("SQpay.merNo")));
		reqMap.put("refundNo", ParamUtils.toString(dataMap.get("merOrderNo")));
		MD5 md5 = new MD5();
		String signTxt = MD5Utils.getMd5Str(reqMap)
				+ (md5.getMD5Info(ParamUtils.toString(PropKit.get("SQpay.MD5Key")))).toUpperCase();

		reqMap.put("MD5Info", md5.getMD5Info(signTxt).toUpperCase());
		// 创建默认的httpClient实例.
        CloseableHttpClient httpclient = HttpClients.createDefault();
        // 创建httppost
        HttpPost httppost = new HttpPost("https://scan.95epay.cn/merRefundQuery.action");
        // 创建参数队列    
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("merchantno", ParamUtils.toString(PropKit.get("SQpay.merNo"))));
        formparams.add(new BasicNameValuePair("refundNo", ParamUtils.toString(reqMap.get("refundNo"))));
        formparams.add(new BasicNameValuePair("md5Info", ParamUtils.toString(reqMap.get("MD5Info"))));
        sendPost(httpclient, httppost, formparams);
}
	
	//退款申请 TODO
	public static void refundApp(Map dataMap) throws Exception {
		// TODO Auto-generated method stub
		Map reqMap = new HashMap();
		reqMap.put("merchantno", ParamUtils.toString(PropKit.get("SQpay.merNo")));
		reqMap.put("merchantOrderNo", ParamUtils.toString(dataMap.get("merOrderNo")));
		reqMap.put("orderNo", ParamUtils.toString(dataMap.get("Orderno")));
		reqMap.put("amount", ParamUtils.toString(dataMap.get("payAmount")));
		MD5 md5 = new MD5();
//		String signTxt = MD5Utils.getMd5Str(reqMap)
//		String signTxt = "amount="+ParamUtils.toString(reqMap.get("amount"))+
//				"&merchantno="+ParamUtils.toString(PropKit.get("SQpay.merNo"))+
//				"&merchantOrderNo="+ParamUtils.toString(reqMap.get("merchantOrderNo"))+
//				"&orderNo="+ParamUtils.toString(reqMap.get("orderNo"))+"&"
		String signTxt = "merchantno="+ParamUtils.toString(PropKit.get("SQpay.merNo"))+
				"&merchantOrderNo="+ParamUtils.toString(reqMap.get("merchantOrderNo"))+
				"&orderNo="+ParamUtils.toString(reqMap.get("orderNo"))+
				"&amount="+ParamUtils.toString(reqMap.get("amount"))+
				"&"
				+ (md5.getMD5Info(ParamUtils.toString(PropKit.get("SQpay.MD5Key")))).toUpperCase();
		
		System.out.println("请求MD5Info       "+signTxt);
		reqMap.put("MD5Info", md5.getMD5Info(signTxt).toUpperCase());
		reqMap.put("refundReason", "测试");
		reqMap.put("tradeDate","");
		// 创建默认的httpClient实例.
        CloseableHttpClient httpclient = HttpClients.createDefault();
        // 创建httppost
        HttpPost httppost = new HttpPost("https://scan.95epay.cn/merApplyRefund.action");
        // 创建参数队列    
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("merchantno", ParamUtils.toString(PropKit.get("SQpay.merNo"))));
        formparams.add(new BasicNameValuePair("merchantOrderNo", ParamUtils.toString(reqMap.get("merchantOrderNo"))));
        formparams.add(new BasicNameValuePair("orderNo", ParamUtils.toString(reqMap.get("orderNo"))));
        formparams.add(new BasicNameValuePair("amount", ParamUtils.toString(reqMap.get("amount"))));
        formparams.add(new BasicNameValuePair("refundReason", ParamUtils.toString(reqMap.get("refundReason"))));
        formparams.add(new BasicNameValuePair("md5Info", ParamUtils.toString(reqMap.get("MD5Info"))));
        formparams.add(new BasicNameValuePair("tradeDate", ParamUtils.toString(reqMap.get("tradeDate"))));
        sendPost(httpclient, httppost, formparams);
	}
	//交易结果查询
	public static void queryPay(Map dataMap) throws Exception {
		Map reqMap = new HashMap();
		reqMap.put("MerNo", ParamUtils.toString(PropKit.get("SQpay.merNo")));
		reqMap.put("BillNo", ParamUtils.toString(dataMap.get("merOrderNo")));
		MD5 md5 = new MD5();
		String signTxt = MD5Utils.getMd5Str(reqMap)
				+ (md5.getMD5Info(ParamUtils.toString(PropKit.get("SQpay.MD5Key")))).toUpperCase();

		reqMap.put("MD5Info", md5.getMD5Info(signTxt).toUpperCase());
		
		// 创建默认的httpClient实例.
        CloseableHttpClient httpclient = HttpClients.createDefault();
        // 创建httppost
        HttpPost httppost = new HttpPost("https://query.95epay.cn/searchInterfaceSingleFR.action");
        // 创建参数队列    
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("merNo", ParamUtils.toString(PropKit.get("SQpay.merNo"))));
        formparams.add(new BasicNameValuePair("BillNo", ParamUtils.toString(reqMap.get("BillNo"))));
        formparams.add(new BasicNameValuePair("MD5Info", ParamUtils.toString(reqMap.get("MD5Info"))));
        sendPost(httpclient, httppost, formparams);
		
}
	//异步通知
	public static void querymsm(Map dataMap) throws Exception {
	// TODO Auto-generated method stub
		
		Map reqMap = new HashMap();
		reqMap.put("MerNo", ParamUtils.toString(PropKit.get("SQpay.merNo")));
		reqMap.put("BillNo", ParamUtils.toString(dataMap.get("merOrderNo")));
		reqMap.put("Amount", ParamUtils.toString(dataMap.get("payAmount")));
		reqMap.put("Succeed", "88");
		MD5 md5 = new MD5();
		String signTxt = MD5Utils.getMd5Str(reqMap)
				+ (md5.getMD5Info(ParamUtils.toString(PropKit.get("SQpay.MD5Key")))).toUpperCase();
		reqMap.put("Orderno", ParamUtils.toString(dataMap.get("Orderno")));
		reqMap.put("Result", "交易成功");
		reqMap.put("bankOrderNo", ParamUtils.toString(dataMap.get("bankOrderNo")));
		reqMap.put("MerRemark", "测试");
		reqMap.put("MD5Info", md5.getMD5Info(signTxt).toUpperCase());
		
		// 创建默认的httpClient实例.
        CloseableHttpClient httpclient = HttpClients.createDefault();
        // 创建httppost
        HttpPost httppost = new HttpPost(ParamUtils.toString(PropKit.get("SQpay.NotifyURL")));
        // 创建参数队列    
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("merNo", ParamUtils.toString(PropKit.get("SQpay.merNo"))));
        formparams.add(new BasicNameValuePair("BillNo", ParamUtils.toString(reqMap.get("BillNo"))));
        formparams.add(new BasicNameValuePair("Amount",  ParamUtils.toString(reqMap.get("Amount"))));
        formparams.add(new BasicNameValuePair("Succeed",  ParamUtils.toString(reqMap.get("Succeed"))));
        formparams.add(new BasicNameValuePair("Orderno", ParamUtils.toString(reqMap.get("Orderno"))));
        formparams.add(new BasicNameValuePair("Result", ParamUtils.toString(reqMap.get("Result"))));
        formparams.add(new BasicNameValuePair("bankOrderNo", ParamUtils.toString(reqMap.get("bankOrderNo"))));
        formparams.add(new BasicNameValuePair("MerRemark", ParamUtils.toString(reqMap.get("MerRemark"))));
        formparams.add(new BasicNameValuePair("MD5Info", ParamUtils.toString(reqMap.get("MD5Info"))));
        sendPost(httpclient, httppost, formparams);
		
}

	//交易接口
	public static void pay(Map dataMap) {
		Map<String, String> reqMap = new HashMap<String, String>();
		reqMap.put("merNo",ParamUtils.toString(PropKit.get("SQpay.merNo")));
		reqMap.put("merOrderNo",ParamUtils.toString(dataMap.get("merOrderNo")));
		reqMap.put("cardNo",ParamUtils.toString(dataMap.get("cardNo")));
		reqMap.put("custName",ParamUtils.toString(dataMap.get("custName")));
		reqMap.put("idType","0");
		reqMap.put("idNo",ParamUtils.toString(dataMap.get("idNo")));
		reqMap.put("phone",ParamUtils.toString(dataMap.get("phoneNo")));
		reqMap.put("payAmount",ParamUtils.toString(dataMap.get("payAmount")));

		Map<String, String> issInsMap = ParamUtils.toMap(new Object[][] { { "6", "BOC" }, { "1", "ICBC" }, { "2", "ABC" },
				{ "7", "BOCOM" }, { "9", "GDB" }, { "4", "CCB" }, { "8", "SPDB" }, { "5", "CMB" }, { "3", "PSBC" },
				{ "10", "CMBC" }, { "13", "CIB" }, { "14", "CITIC" }, { "84", "HXB" }, { "12", "CEB" },
				{ "75", "BCCB" }, { "15", "BOS" }, { "11", "PAB" }, { "68", "CZBANK" }, { "76", "JXBANK" } });

		if ("".equals(ParamUtils.toString(issInsMap.get(ParamUtils.toString(dataMap.get("bankCode")))))) {
			throw new RuntimeException("暂时不支持该银行卡");
		}
		
		reqMap.put("bankCode", ParamUtils.toString(dataMap.get("bankCode")));
		reqMap.put("payType","XYPAY");
		reqMap.put("NotifyURL", ParamUtils.toString(PropKit.get("SQpay.NotifyURL")));
		reqMap.put("purpose","订单支付");
		
		
		reqMap.put("txnTime",ParamUtils.toString(dataMap.get("txnTime")));
		reqMap.put("smsCode",ParamUtils.toString(dataMap.get("smsCode")));
		
		StringBuffer buffer	= new StringBuffer();
		buffer.append("merNo=").append(ParamUtils.toString(PropKit.get("SQpay.merNo"))).append("&");
		buffer.append("merOrderNo=").append(ParamUtils.toString(reqMap.get("merOrderNo"))).append("&");
		buffer.append("custName=").append(ParamUtils.toString(reqMap.get("custName"))).append("&");
		buffer.append("phone=").append(ParamUtils.toString(reqMap.get("phone"))).append("&");
		buffer.append("cardNo=").append(ParamUtils.toString(reqMap.get("cardNo"))).append("&");
		buffer.append("idType=").append("0").append("&");
		buffer.append("idNo=").append(ParamUtils.toString(reqMap.get("idNo"))).append("&");
		buffer.append("payAmount=").append(ParamUtils.toString(reqMap.get("payAmount"))).append("&");
		buffer.append("bankCode=").append(ParamUtils.toString(reqMap.get("bankCode"))).append("&");
		buffer.append("NotifyURL=").append(ParamUtils.toString(PropKit.get("SQpay.NotifyURL"))).append("&");
		
		MD5 md5 = new MD5();
		String signTxt = buffer.toString() + (md5.getMD5Info(ParamUtils.toString(PropKit.get("SQpay.MD5Key")))).toUpperCase();

		reqMap.put("MD5Info",md5.getMD5Info(signTxt).toUpperCase());
		
		// 创建默认的httpClient实例.
        CloseableHttpClient httpclient = HttpClients.createDefault();
        // 创建httppost
        HttpPost httppost = new HttpPost("https://fastpay.95epay.cn/pay/hfDaikouTrade.action");
        
        // 创建参数队列    
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("merNo", ParamUtils.toString(PropKit.get("SQpay.merNo"))));
        formparams.add(new BasicNameValuePair("custName", ParamUtils.toString(reqMap.get("custName"))));
        formparams.add(new BasicNameValuePair("cardNo",  ParamUtils.toString(reqMap.get("cardNo"))));
        formparams.add(new BasicNameValuePair("phone",  ParamUtils.toString(reqMap.get("phone"))));
        formparams.add(new BasicNameValuePair("idNo", ParamUtils.toString(reqMap.get("idNo"))));
        formparams.add(new BasicNameValuePair("idType", ParamUtils.toString(reqMap.get("idType"))));
        formparams.add(new BasicNameValuePair("payAmount", ParamUtils.toString(reqMap.get("payAmount"))));
        formparams.add(new BasicNameValuePair("merOrderNo", ParamUtils.toString(reqMap.get("merOrderNo"))));
        formparams.add(new BasicNameValuePair("bankCode", ParamUtils.toString(reqMap.get("bankCode"))));
        formparams.add(new BasicNameValuePair("payType", ParamUtils.toString(reqMap.get("payType"))));
        formparams.add(new BasicNameValuePair("NotifyURL", ParamUtils.toString(PropKit.get("SQpay.NotifyURL"))));
        formparams.add(new BasicNameValuePair("txnTime", ParamUtils.toString(reqMap.get("txnTime"))));
        formparams.add(new BasicNameValuePair("smsCode", ParamUtils.toString(reqMap.get("smsCode"))));
        formparams.add(new BasicNameValuePair("purpose", ParamUtils.toString(reqMap.get("purpose"))));
        formparams.add(new BasicNameValuePair("MD5Info", ParamUtils.toString(reqMap.get("MD5Info"))));
        sendPost(httpclient, httppost, formparams);
		
}


	//支付短信
	public static void payMsg(Map dataMap) throws Exception {
		Map<String, String> reqMap = new HashMap<String, String>();
		reqMap.put("custName",ParamUtils.toString(dataMap.get("custName")));
		reqMap.put("cardNo",ParamUtils.toString(dataMap.get("cardNo")));
		reqMap.put("phone",ParamUtils.toString(dataMap.get("phoneNo")));
		reqMap.put("idNo",ParamUtils.toString(dataMap.get("idNo")));
		reqMap.put("idType", "0");
		reqMap.put("payAmount",ParamUtils.toString(dataMap.get("payAmount")));
		reqMap.put("merOrderNo",ParamUtils.toString(dataMap.get("merOrderNo")));

		Map<String, String> issInsMap = ParamUtils.toMap(new Object[][] { { "6", "BOC" }, { "1", "ICBC" }, { "2", "ABC" },
				{ "7", "BOCOM" }, { "9", "GDB" }, { "4", "CCB" }, { "8", "SPDB" }, { "5", "CMB" }, { "3", "PSBC" },
				{ "10", "CMBC" }, { "13", "CIB" }, { "14", "CITIC" }, { "84", "HXB" }, { "12", "CEB" },
				{ "75", "BCCB" }, { "15", "BOS" }, { "11", "PAB" }, { "68", "CZBANK" }, { "76", "JXBANK" } });

		if ("".equals(ParamUtils.toString(issInsMap.get(ParamUtils.toString(dataMap.get("bankCode")))))) {
			throw new RuntimeException("暂时不支持该银行卡");
		}
	
		reqMap.put("cardType", "1");
		reqMap.put("transDate",ParamUtils.getFormatDate(new Date(), ParamUtils.getDate.DATE_YYYYMMDD));
		reqMap.put("transTime", ParamUtils.getFormatDate(new Date(), ParamUtils.getDate.DATE_HHMMSS));
		reqMap.put("bankCode",ParamUtils.toString(dataMap.get("bankCode")));
		reqMap.put("payType", "XYPAY");
		reqMap.put("NotifyURL", ParamUtils.toString(PropKit.get("SQpay.NotifyURL")));
		reqMap.put("purpose","");
		
		reqMap.put("year","");
		reqMap.put("month","");
		reqMap.put("CVV2","");
		
		StringBuffer buffer = new StringBuffer();
		buffer.append("merNo=").append(ParamUtils.toString(PropKit.get("SQpay.merNo"))).append("&");
		buffer.append("custName=").append(ParamUtils.toString(reqMap.get("custName"))).append("&");
		buffer.append("phone=").append(ParamUtils.toString(reqMap.get("phone"))).append("&");
		buffer.append("cardNo=").append(ParamUtils.toString(reqMap.get("cardNo"))).append("&");
		buffer.append("idNo=").append(ParamUtils.toString(reqMap.get("idNo"))).append("&");
		buffer.append("idType=").append("0").append("&");
		buffer.append("payAmount=").append(ParamUtils.toString(reqMap.get("payAmount"))).append("&");
		buffer.append("merOrderNo=").append(ParamUtils.toString(reqMap.get("merOrderNo"))).append("&");
		buffer.append("cardType=").append("1").append("&");
		buffer.append("year=").append("").append("&");
		buffer.append("month=").append("").append("&");
		buffer.append("CVV2=").append("").append("&");
		buffer.append("transDate=").append(ParamUtils.toString(reqMap.get("transDate"))).append("&");
		buffer.append("transTime=").append(ParamUtils.toString(reqMap.get("transTime"))).append("&");
		
		MD5 md5 = new MD5();
		String signTxt = buffer.toString() + (md5.getMD5Info(ParamUtils.toString(PropKit.get("SQpay.MD5Key")))).toUpperCase();
		reqMap.put("MD5Info", md5.getMD5Info(signTxt).toUpperCase());
		

		// 创建默认的httpClient实例.
        CloseableHttpClient httpclient = HttpClients.createDefault();
        // 创建httppost
        HttpPost httppost = new HttpPost("https://fastpay.95epay.cn/pay/realnameAuth.action");
        
        // 创建参数队列    
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("merNo", ParamUtils.toString(PropKit.get("SQpay.merNo"))));
        formparams.add(new BasicNameValuePair("custName", ParamUtils.toString(reqMap.get("custName"))));
        formparams.add(new BasicNameValuePair("cardNo",  ParamUtils.toString(reqMap.get("cardNo"))));
        formparams.add(new BasicNameValuePair("phone",  ParamUtils.toString(reqMap.get("phone"))));
        formparams.add(new BasicNameValuePair("idNo", ParamUtils.toString(reqMap.get("idNo"))));
        formparams.add(new BasicNameValuePair("idType", ParamUtils.toString(reqMap.get("idType"))));
        formparams.add(new BasicNameValuePair("payAmount", ParamUtils.toString(reqMap.get("payAmount"))));
        formparams.add(new BasicNameValuePair("merOrderNo", ParamUtils.toString(reqMap.get("merOrderNo"))));
        formparams.add(new BasicNameValuePair("bankCode", ParamUtils.toString(reqMap.get("bankCode"))));
        formparams.add(new BasicNameValuePair("payType", ParamUtils.toString(reqMap.get("payType"))));
        formparams.add(new BasicNameValuePair("cardType", ParamUtils.toString(reqMap.get("cardType"))));
        formparams.add(new BasicNameValuePair("NotifyURL", ParamUtils.toString(PropKit.get("SQpay.NotifyURL"))));
        formparams.add(new BasicNameValuePair("transDate", ParamUtils.toString(reqMap.get("transDate"))));
        formparams.add(new BasicNameValuePair("transTime", ParamUtils.toString(reqMap.get("transTime"))));
        formparams.add(new BasicNameValuePair("purpose", ParamUtils.toString(reqMap.get("purpose"))));
        formparams.add(new BasicNameValuePair("MD5Info", ParamUtils.toString(reqMap.get("MD5Info"))));
        sendPost(httpclient, httppost, formparams);
}
	
	public static void sendPost(CloseableHttpClient httpclient, HttpPost httppost, List<NameValuePair> formparams) {
		UrlEncodedFormEntity uefEntity;  
		Map<String,String> map = null;
        try {  
        	System.out.println("请求"+formparams.toString());
            uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");  
            httppost.setEntity(uefEntity);  
            System.out.println("executing request " + httppost.getURI());  
            CloseableHttpResponse response = httpclient.execute(httppost);  
            try {
                HttpEntity entity = response.getEntity();
                if (entity != null) {
                	 String str = EntityUtils.toString(entity, "UTF-8");
                    System.out.println("--------------------------------------");
                    System.out.println("Response content: " + str);
                    System.out.println("--------------------------------------");
                    
                    
                    String strs = str.substring(str.indexOf("State")+7, str.indexOf("State")+8);
                    String strs1 = str.substring(str.indexOf("message")+9, str.indexOf("message")+13);
                    System.out.println(strs1);
                    System.out.println(strs);
//                    map = new HashMap<String,String>();
//            		for(String s : strs){
//            			String[] s1 = s.split("\":\"");
//            			map.put(s1[0], s1[1]);
//            		}
            		
                }
//                return map;
                
            } finally {
                response.close();
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            // 关闭连接,释放资源 
            try {
                httpclient.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
//		return map;
	}

	//解约
	public static void breakContract(Map<String,String> dataMap) throws Exception {
		// TODO Auto-generated method stub
		Map<String, String> reqMap = new HashMap<String, String>();
		reqMap.put("merNo", ParamUtils.toString(PropKit.get("SQpay.merNo")));
		reqMap.put("custName", ParamUtils.toString(dataMap.get("custName")));
		reqMap.put("phoneNo", ParamUtils.toString(dataMap.get("phoneNo")));
		reqMap.put("cardNo", ParamUtils.toString(dataMap.get("cardNo")));
		reqMap.put("idNo", ParamUtils.toString(dataMap.get("idNo")));
		reqMap.put("reqMsgId", ParamUtils.getFormatDate(new Date(), ParamUtils.getDate.DATE_YYYYMMDD) + ParamUtils.getRandom(6));
		reqMap.put("payType", "XYPAY");
		MD5 md5 = new MD5();
		String signTxt = MD5Utils.getMd5Str(reqMap)
				+ (md5.getMD5Info(ParamUtils.toString(PropKit.get("SQpay.MD5Key")))).toUpperCase();
		reqMap.put("MD5Info", md5.getMD5Info(signTxt).toUpperCase());

		System.out.println("signTxt"+ParamUtils.toString(reqMap.get("MD5Info")));
		// 创建默认的httpClient实例.
        CloseableHttpClient httpclient = HttpClients.createDefault();
        // 创建httppost
        HttpPost httppost = new HttpPost("https://fastpay.95epay.cn/pay/breakBindCard.action");
        
        // 创建参数队列    
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("cardNo",  ParamUtils.toString(reqMap.get("cardNo"))));
        formparams.add(new BasicNameValuePair("custName", ParamUtils.toString(reqMap.get("custName"))));
        formparams.add(new BasicNameValuePair("idNo", ParamUtils.toString(reqMap.get("idNo"))));
        formparams.add(new BasicNameValuePair("merNo", ParamUtils.toString(reqMap.get("merNo"))));
        formparams.add(new BasicNameValuePair("payType", ParamUtils.toString(reqMap.get("payType"))));
        formparams.add(new BasicNameValuePair("phoneNo", ParamUtils.toString(reqMap.get("phoneNo"))));
        formparams.add(new BasicNameValuePair("reqMsgId", ParamUtils.toString(reqMap.get("reqMsgId"))));  
        formparams.add(new BasicNameValuePair("MD5Info", ParamUtils.toString(reqMap.get("MD5Info"))));
        sendPost(httpclient, httppost, formparams);
	}
	//查询签约
	//签约查询
	public static void querySignResult(Map<String,String> dataMap) throws Exception{
		
		Map<String, String> reqMap = new HashMap<String, String>();
		reqMap.put("merNo", ParamUtils.toString(PropKit.get("SQpay.merNo")));
		reqMap.put("custName", ParamUtils.toString(dataMap.get("custName")));
		reqMap.put("phoneNo", ParamUtils.toString(dataMap.get("phoneNo")));
		reqMap.put("cardNo", ParamUtils.toString(dataMap.get("cardNo")));
		reqMap.put("idNo", ParamUtils.toString(dataMap.get("idNo")));
		reqMap.put("payType", "XYPAY");

		MD5 md5 = new MD5();
		String signTxt = MD5Utils.getMd5Str(reqMap)
				+ (md5.getMD5Info(ParamUtils.toString(PropKit.get("SQpay.MD5Key")))).toUpperCase();

		reqMap.put("MD5Info", md5.getMD5Info(signTxt).toUpperCase());
		reqMap.put("payAmount", ParamUtils.toString(dataMap.get("payAmount")));

		
		// 创建默认的httpClient实例.
        CloseableHttpClient httpclient = HttpClients.createDefault();
        // 创建httppost
        HttpPost httppost = new HttpPost("https://fastpay.95epay.cn/pay/querySignResult.action");
        // 创建参数队列    
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("merNo", reqMap.get("merNo")));
        formparams.add(new BasicNameValuePair("custName", reqMap.get("custName")));
        formparams.add(new BasicNameValuePair("phoneNo", reqMap.get("phoneNo")));
        formparams.add(new BasicNameValuePair("cardNo", reqMap.get("cardNo")));
        formparams.add(new BasicNameValuePair("idNo", reqMap.get("idNo")));
        formparams.add(new BasicNameValuePair("MD5Info", reqMap.get("MD5Info")));
        formparams.add(new BasicNameValuePair("payAmount", reqMap.get("payAmount")));  
        formparams.add(new BasicNameValuePair("payType", reqMap.get("payType")));
        
        sendPost(httpclient, httppost, formparams);
	}
	//签约/认证custType 02签约  01认证
	//签约/认证      custType 02签约  01认证
	public static void Contract(Map<String,String> dataMap) throws Exception {
		
		Map<String, String> reqMap = new HashMap<String, String>();
		reqMap.put("merNo", ParamUtils.toString(PropKit.get("SQpay.merNo")));
		reqMap.put("custName", ParamUtils.toString(dataMap.get("custName")));
		reqMap.put("phoneNo", ParamUtils.toString(dataMap.get("phoneNo")));
		reqMap.put("cardNo", ParamUtils.toString(dataMap.get("cardNo")));
		Map<String, String> issInsMap = ParamUtils.toMap(new Object[][] { { "6", "BOC" }, { "1", "ICBC" }, { "2", "ABC" },
				{ "7", "BOCOM" }, { "9", "GDB" }, { "4", "CCB" }, { "8", "SPDB" }, { "5", "CMB" }, { "3", "PSBC" },
				{ "10", "CMBC" }, { "13", "CIB" }, { "14", "CITIC" }, { "84", "HXB" }, { "12", "CEB" },
				{ "75", "BCCB" }, { "15", "BOS" }, { "11", "PAB" }, { "68", "CZBANK" }, { "76", "JXBANK" } });

		if ("".equals(ParamUtils.toString(issInsMap.get(ParamUtils.toString(dataMap.get("bankCode")))))) {
			throw new RuntimeException("暂时不支持该银行卡");
		}

		reqMap.put("bankCode", ParamUtils.toString(dataMap.get("bankCode")));
		reqMap.put("idNo", ParamUtils.toString(dataMap.get("idNo")));
		reqMap.put("idType", "0");
		reqMap.put("reqMsgId", ParamUtils.getFormatDate(new Date(), ParamUtils.getDate.DATE_YYYYMMDD) + ParamUtils.getRandom(6));
		reqMap.put("cardType", "1");
		reqMap.put("authMsg", "075216");
		reqMap.put("custType", "01");
		reqMap.put("payType", "XYPAY");

		MD5 md5 = new MD5();
		String signTxt = MD5Utils.getMd5Str(reqMap)
				+ (md5.getMD5Info(ParamUtils.toString(PropKit.get("SQpay.MD5Key")))).toUpperCase();
		reqMap.put("MD5Info", md5.getMD5Info(signTxt).toUpperCase());

		
        // 创建默认的httpClient实例.
        CloseableHttpClient httpclient = HttpClients.createDefault();
        // 创建httppost
        HttpPost httppost = new HttpPost("https://fastpay.95epay.cn/pay/identifyAuthAndSign.action");
        // 创建参数队列    
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("merNo", ParamUtils.toString(reqMap.get("merNo"))));
        formparams.add(new BasicNameValuePair("custName", ParamUtils.toString(reqMap.get("custName"))));
        formparams.add(new BasicNameValuePair("phoneNo", ParamUtils.toString(reqMap.get("phoneNo"))));
        formparams.add(new BasicNameValuePair("cardNo", ParamUtils.toString(reqMap.get("cardNo"))));
        formparams.add(new BasicNameValuePair("bankCode", ParamUtils.toString(reqMap.get("bankCode"))));
        formparams.add(new BasicNameValuePair("idNo", ParamUtils.toString(reqMap.get("idNo"))));
        formparams.add(new BasicNameValuePair("idType", ParamUtils.toString(reqMap.get("idType"))));  
        formparams.add(new BasicNameValuePair("reqMsgId", ParamUtils.toString(reqMap.get("reqMsgId"))));
        formparams.add(new BasicNameValuePair("cardType", ParamUtils.toString(reqMap.get("cardType"))));  
        formparams.add(new BasicNameValuePair("authMsg", ParamUtils.toString(reqMap.get("authMsg"))));
        formparams.add(new BasicNameValuePair("custType", ParamUtils.toString(reqMap.get("custType"))));  
        formparams.add(new BasicNameValuePair("payType", ParamUtils.toString(reqMap.get("payType"))));
        formparams.add(new BasicNameValuePair("MD5Info", ParamUtils.toString(reqMap.get("MD5Info"))));
        
        sendPost(httpclient, httppost, formparams);
	}
	


}
